/**
 * CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

package com.cmcc.zysoft.infocollection.mobile.service;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cmcc.zysoft.framework.utils.StringUtil;
import com.cmcc.zysoft.infocollection.constant.URLConstant;
import com.cmcc.zysoft.infocollection.mobile.dao.MResourceDao;
import com.cmcc.zysoft.infocollection.model.Areas;
import com.cmcc.zysoft.infocollection.model.Industry;
import com.cmcc.zysoft.infocollection.model.Resource;
import com.cmcc.zysoft.infocollection.model.ServiceItem;
import com.cmcc.zysoft.infocollection.model.SystemUser;
import com.starit.common.dao.hibernate.HibernateBaseDao;
import com.starit.common.dao.service.BaseServiceImpl;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 袁凤建
 * <br />邮箱: yuan.fengjian@ustcinfo.com
 * <br />描述: MResourceService.java
 * <br />版本: 1.0.0
 * <br />日期: 2013-8-12 下午4:40:18
 * <br />CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

@Service
public class MResourceService extends BaseServiceImpl<Resource, String> {
	
	/**
	 * 添加商户接口URL前缀.
	 */
	@Value("${insert.resource.url.prefix}")
	private String insertResourceUrlPrefix;
	
	/**
	 * 更新商户信息接口URL前缀.
	 */
	@Value("${update.resource.url.prefix}")
	private String updateResourceUrlPrefix;
	
	/**
	 * 生活(商户)搜索接口URL.
	 */
	@Value("${search.shop.url}")
	private String searchShopUrl;
	
	/**
	 * 商户详情接口URL.
	 */
	@Value("${shop.detail.url}")
	private String shopDetailUrl;
	
	/**
	 * 日志.
	 */
	private static final Logger logger = LoggerFactory.getLogger(MResourceService.class);

	/**
	 * 属性名称: mResourceDao.
	 * 类       型: MResourceDao.
	 */
	@javax.annotation.Resource
	private MResourceDao mResourceDao;
	
	/**
	 * 属性名称: mAreasService.
	 * 类       型: MAreasService.
	 */
	@javax.annotation.Resource
	private MAreasService mAreasService;
	
	/**
	 * 属性名称: mCitiesService.
	 * 类       型: MCitiesService.
	 */
	@javax.annotation.Resource
	private MCitiesService mCitiesService;
	
	/**
	 * 属性名称: mSystemUserService.
	 * 类       型: MSystemUserService.
	 */
	@javax.annotation.Resource
	private MSystemUserService mSystemUserService;
	
	/**
	 * 属性名称: mServiceItemService.
	 * 类       型: MServiceItemService.
	 */
	@javax.annotation.Resource
	private MServiceItemService mServiceItemService;
	
	/**
	 * 属性名称: mResourcePropertyService.
	 * 类       型: MResourcePropertyService.
	 */
	@javax.annotation.Resource
	private MResourcePropertyService mResourcePropertyService;
	
	@Override
	public HibernateBaseDao<Resource, String> getHibernateBaseDao() {
		return this.mResourceDao;
	}
	
	/**
	 * 个人中心-通过该接口,用户可查询自己的POI采集和更新信息(审核不通过的不计入统计范围).
	 * @param usercode 手机号
	 * @return map
	 */
	@Transactional
	public Map<String, Object> statCenter(String usercode) {
		Map<String, Object> map = new HashMap<String, Object>();
		List<SystemUser> list = this.mSystemUserService.findByNamedParam(new String[]{"userName", "delFlag"}, new Object[]{usercode, "0"});
		if(!list.isEmpty()) {
			List<Map<String, Object>> result = this.mResourceDao.statCenter(list.get(0).getUserId());
			map.put("status", "1");
			map.put("result", result);
		} else {
			map.put("status", "2");
			map.put("message", "用户不存在或已删除");
		}
		return map;
	}
	
	
	/**
	 * 信息新增接口-通过该接口向中央信息库中新增商户信息,并将商户信息持久化至本地数据库(先中央库,再本地库).
	 * @param userId 用户ID
	 * @param caterReg 区/县ID
	 * @param caterServ 服务项目ID
	 * @param caterName 商户名称
	 * @param caterStore 分店名
	 * @param shortName 别名简称
	 * @param caterMobile 联系电话
	 * @param caterDetailAdd 详细地址
	 * @param caterBusi 商圈
	 * @param caterBuild 标志性建筑
	 * @param caterZip 邮编
	 * @param caterTime 营业时间
	 * @param caterTransit 公交路线
	 * @param caterDesc 位置描述
	 * @param caterAtmo 商户氛围
	 * @param caterReco 推荐点
	 * @param caterMerIntr 商户简介
	 * @param caterbiaoqian 标签
	 * @param caterDish 招牌菜
	 * @param caterPark 停车位
	 * @param caterLevel 消费档次
	 * @param caterSwingCard 是否刷卡
	 * @param caterArea 面积(m2)
	 * @param caterRoom 包间信息
	 * @param caterBigRoom 大包间
	 * @param caterSmallRoom 小包间
	 * @param caterSeatCap 客容量
	 * @param caterAccReser 是否接受预定
	 * @param caterDeliServ 是否外送服务
	 * @param caterInfoMainte 信息维护
	 * @param x 经度
	 * @param y 纬度
	 * @param mobilePayment 是否手机支付
	 * @return String
	 */
	@Transactional
	public String addResourceLocal(String userId, String caterReg, String caterServ, String caterName, String caterStore, 
			String shortName, String caterMobile, String caterDetailAdd, String caterBusi, String caterBuild, String caterZip, 
			String caterTime, String caterTransit, String caterDesc, String caterAtmo, String caterReco, String caterMerIntr, 
			String caterbiaoqian, String caterDish, String caterPark, String caterLevel, String caterSwingCard, String caterArea, 
			String caterRoom, String caterBigRoom, String caterSmallRoom, String caterSeatCap, String caterAccReser, 
			String caterDeliServ, String caterInfoMainte, String x, String y, String mobilePayment) {
		Resource resource = new Resource();
		//替换营业时间中的中文冒号为英文冒号
		caterTime = caterTime.replaceAll("：", ":");
		String provinceId = ""; //省份ID
		String cityId = ""; //城市ID
		String industryId = ""; //行业ID
		String channelId = ""; //频道ID
		String dataSource = URLConstant.DATA_SOURCE; //数据来源(1-安徽)
		if(StringUtils.hasText(caterReg)) {
			//根据区域ID查找区域信息
			Areas areas = this.mAreasService.getAreaById(caterReg);
			cityId = areas.getCityid();
			provinceId = areas.getProvinceid();
		}
		resource.setProvinceId(provinceId);
		resource.setCityId(cityId);
		resource.setDistrictId(caterReg);
		if(StringUtils.hasText(caterServ)) {
			//根据服务项目ID获取服务项目信息
			ServiceItem serviceItem = this.mServiceItemService.getEntity(caterServ);
			industryId = serviceItem.getIndustry().getIndustryId();
			channelId = serviceItem.getIndustry().getChannel().getChannelId();
		}
		resource.setChannelId(channelId);
		resource.setTradeId(industryId);
		resource.setBelongId(caterServ);
		resource.setName(caterName);
		resource.setBranchName(caterStore);
		resource.setShortName(shortName);
		resource.setTelno(caterMobile);
		resource.setAddress(caterDetailAdd);
		resource.setRegion(caterBusi);
		resource.setLandmark(caterBuild);
		resource.setZipcode(caterZip);
		resource.setOpenTime(caterTime);
		resource.setBusRoute(caterTransit);
		resource.setRoute(caterDesc);
		resource.setFeature(caterAtmo);
		resource.setRecommendation(caterReco);
		resource.setIntroduction(caterMerIntr);
		resource.setTag(caterbiaoqian);
		resource.setSpecialOffer(caterDish); //招牌菜/特色菜
		resource.setParking(caterPark);
		resource.setCost(caterLevel);
		resource.setChargeType(caterSwingCard); //是否刷卡
		resource.setArea(caterArea);
		resource.setPrivateRoom(caterRoom);
		resource.setMaxCapacity(caterBigRoom);
		resource.setMinCapacity(caterSmallRoom);
		resource.setCapacity(caterSeatCap);
		resource.setReservation(caterAccReser);
		resource.setDeliveryService(caterDeliServ);
		resource.setInfoMaintain(caterInfoMainte);
		resource.setX(x);
		resource.setY(y);
		resource.setMobilePayment(mobilePayment);
		resource.setAddMan(userId);
		resource.setAddDate(new Date());
		resource.setDataSource(dataSource);
		resource.setCheckFlag("1"); //是否经过审核(0-是,1-否)
		resource.setDataFlag("0"); //数据标识(0-新增、1-更新、2-删除或为空白)
		resource.setDelFlag("0"); //删除标志(0-未删除 1-已删除)
		resource.setPassFlag("0"); //审核结果(0-默认值,1-通过,-1-不通过)
		resource.setCollectorId(URLConstant.COLLECTOR_ID);
		String result = "";
		try {
			//向中央信息库中新增商户信息
			result = this.addResourceCenter(userId, caterReg, caterServ, caterName, caterStore, shortName, caterMobile, 
					caterDetailAdd, caterBusi, caterBuild, caterZip, caterTime, caterTransit, caterDesc, caterAtmo, 
					caterReco, caterMerIntr, caterbiaoqian, caterDish, caterPark, caterLevel, caterSwingCard, caterArea, 
					caterRoom, caterBigRoom, caterSmallRoom, caterSeatCap, caterAccReser, caterDeliServ, caterInfoMainte, 
					x, y, mobilePayment, provinceId, cityId, industryId, channelId, dataSource);
			//解析中央库返回的json数据
			JSONObject object = JSONObject.parseObject(result);
			//向中央信息库中新增商户信息成功,将商户信息持久化至数据库
			if("1".equals(object.get("status").toString())) {
				String infoId = ""; //流水号
				String state = ""; //入库状态(1-入库等待,2-入库中,3-入库完成,4-入库失败)
				JSONArray object2 = object.getJSONArray("result");
				for(int i = 0; i < object2.size(); i++) {
					JSONObject config = object2.getJSONObject(i);
		        	state = config.getString("state");
		        	infoId = config.getString("info_id");
				}
				resource.setInfoId(infoId);
				resource.setState(state);
				this.mResourceDao.save(resource);
			}
			logger.debug("#########  向中央信息库中新增商户信息成功!  #########");
		} catch (Exception e) {
			e.printStackTrace();
			logger.debug("#########  向中央信息库中新增商户信息失败!  #########");
		}
		return result;
	}
	
	/**
	 * 信息新增接口-向中央信息库中新增商户信息.
	 * @param userId 用户ID
	 * @param caterReg 区/县ID
	 * @param caterServ 服务项目ID
	 * @param caterName 商户名称
	 * @param caterStore 分店名
	 * @param shortName 别名简称
	 * @param caterMobile 联系电话
	 * @param caterDetailAdd 详细地址
	 * @param caterBusi 商圈
	 * @param caterBuild 标志性建筑
	 * @param caterZip 邮编
	 * @param caterTime 营业时间
	 * @param caterTransit 公交路线
	 * @param caterDesc 位置描述
	 * @param caterAtmo 商户氛围
	 * @param caterReco 推荐点
	 * @param caterMerIntr 商户简介
	 * @param caterbiaoqian 标签
	 * @param caterDish 招牌菜
	 * @param caterPark 停车位
	 * @param caterLevel 消费档次
	 * @param caterSwingCard 是否刷卡
	 * @param caterArea 面积(m2)
	 * @param caterRoom 包间信息
	 * @param caterBigRoom 大包间
	 * @param caterSmallRoom 小包间
	 * @param caterSeatCap 客容量
	 * @param caterAccReser 是否接受预定
	 * @param caterDeliServ 是否外送服务
	 * @param caterInfoMainte 信息维护
	 * @param x 经度
	 * @param y 纬度
	 * @param mobilePayment 是否手机支付
	 * @param provinceId 省份ID
	 * @param cityId 城市ID
	 * @param industryId 行业ID
	 * @param channelId 频道ID
	 * @param dataSource 数据来源
	 * @return String
	 * @throws Exception
	 */
	@Transactional
	public String addResourceCenter(String userId, String caterReg, String caterServ, String caterName, String caterStore, 
			String shortName, String caterMobile, String caterDetailAdd, String caterBusi, String caterBuild, String caterZip, 
			String caterTime, String caterTransit, String caterDesc, String caterAtmo, String caterReco, String caterMerIntr, 
			String caterbiaoqian, String caterDish, String caterPark, String caterLevel, String caterSwingCard, String caterArea, 
			String caterRoom, String caterBigRoom, String caterSmallRoom, String caterSeatCap, String caterAccReser, 
			String caterDeliServ, String caterInfoMainte, String x, String y, String mobilePayment, String provinceId, 
			String cityId, String industryId, String channelId, String dataSource) throws Exception {
		System.out.println("================================================================================");
		System.out.println("编码前name : " + caterName);
		System.out.println("编码前caterPark : " + caterPark);
		System.out.println("编码前caterArea : " + caterArea);
		System.out.println("编码前caterSwingCard : " + caterSwingCard);
		System.out.println("编码前mobilePayment : " + mobilePayment);
		System.out.println("编码前caterAccReser : " + caterAccReser);
		System.out.println("编码前caterDeliServ : " + caterDeliServ);
		System.out.println("================================================================================");
		String xyLevel = URLConstant.XY_LEVEL;
		String isOutbound = URLConstant.IS_OUT_BOUND;
		String ticketPrice = URLConstant.TICKET_PRICE;
		String officialSite = URLConstant.OFFICIAL_SITE;
		userId = URLConstant.COLLECTOR_ID;
		caterName = URLEncoder.encode(caterName, "UTF-8");
		caterStore = URLEncoder.encode(caterStore, "UTF-8");
		shortName = URLEncoder.encode(shortName, "UTF-8");
		caterDetailAdd = URLEncoder.encode(caterDetailAdd, "UTF-8");
		caterBusi = URLEncoder.encode(caterBusi, "UTF-8");
		caterBuild = URLEncoder.encode(caterBuild, "UTF-8");
		caterTransit = URLEncoder.encode(caterTransit, "UTF-8");
		caterDesc = URLEncoder.encode(caterDesc, "UTF-8");
		caterAtmo = URLEncoder.encode(caterAtmo, "UTF-8");
		caterReco = URLEncoder.encode(caterReco, "UTF-8");
		caterMerIntr = URLEncoder.encode(caterMerIntr, "UTF-8");
		caterbiaoqian = URLEncoder.encode(caterbiaoqian, "UTF-8");
		caterDish = URLEncoder.encode(caterDish, "UTF-8");
		caterPark = URLEncoder.encode(caterPark, "UTF-8");
		caterLevel = URLEncoder.encode(caterLevel, "UTF-8");
		caterSwingCard = URLEncoder.encode(caterSwingCard, "UTF-8");
		caterTime = URLEncoder.encode(caterTime, "UTF-8");
		caterArea = URLEncoder.encode(caterArea, "UTF-8");
		caterRoom = URLEncoder.encode(caterRoom, "UTF-8");
		caterAccReser = URLEncoder.encode(caterAccReser, "UTF-8");
		caterDeliServ = URLEncoder.encode(caterDeliServ, "UTF-8");
		caterInfoMainte = URLEncoder.encode(caterInfoMainte, "UTF-8");
		mobilePayment = URLEncoder.encode(mobilePayment, "UTF-8");
		System.out.println("================================================================================");
		System.out.println("编码后name : " + caterName);
		System.out.println("编码后caterPark : " + caterPark);
		System.out.println("编码后caterArea : " + caterArea);
		System.out.println("编码后caterSwingCard : " + caterSwingCard);
		System.out.println("编码后mobilePayment : " + mobilePayment);
		System.out.println("编码后caterAccReser : " + caterAccReser);
		System.out.println("编码后caterDeliServ : " + caterDeliServ);
		System.out.println("================================================================================");
		//URL前缀
		String url = insertResourceUrlPrefix;
		System.out.println("================================================================================");
		System.out.println("新增商户URL : " + insertResourceUrlPrefix);
		System.out.println("================================================================================");
		//URL参数
		String parameters = StringUtil.formatMsg(URLConstant.INSERT_RESOURCE_URL_PARAMETER, caterName, caterMobile, caterDetailAdd, 
				caterStore, shortName, caterMerIntr, caterReco, caterAtmo, caterDish, provinceId, cityId, caterReg, channelId, 
				industryId, caterServ, x, y, caterBuild, caterBusi, xyLevel, caterbiaoqian, userId, isOutbound, caterZip, caterPark, 
				caterSwingCard, caterTime, caterTransit, caterDesc, caterLevel, caterArea, caterRoom, ticketPrice, caterBigRoom, 
				caterSmallRoom, caterSeatCap, caterAccReser, caterDeliServ, officialSite, mobilePayment, caterInfoMainte, dataSource);
		//处理参数中的空格(" "),解决505错误问题(使用%20替换空格)
		parameters = parameters.replaceAll(" ", "%20");
		URL postUrl = new URL(url);
		HttpURLConnection connection = (HttpURLConnection) postUrl.openConnection();
		connection.setDoOutput(true);
		connection.setDoInput(true);
		connection.setInstanceFollowRedirects(false);
		connection.setRequestMethod("POST");
		connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
		connection.setRequestProperty("charset", "UTF-8");
		connection.setRequestProperty("Content-Length", "" + Integer.toString(parameters.getBytes().length));
		connection.setUseCaches(false);
		DataOutputStream out = new DataOutputStream(connection.getOutputStream());
		out.writeBytes(parameters);
		out.flush();
		out.close();
		BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
        String line = "";
        String response = "";
        while ((line = reader.readLine()) != null) {
        	response = line;
        }
        reader.close();
        connection.disconnect();
		System.out.println("================================================================================");
		System.out.println("url : " + (url + "?" + parameters));
		System.out.println("================================================================================");
		System.out.println("返回结果result : " + response);
		System.out.println("================================================================================");
		return response;
	}
	
	/**
	 * 信息更新接口-通过该接口,更新中央信息库中的商户信息,并将商户信息持久化至本地数据库.
	 * @param userId 用户ID
	 * @param shopId 商户ID
	 * @param caterReg 区/县ID
	 * @param caterServ 服务项目ID
	 * @param caterName 商户名称
	 * @param caterStore 分店名
	 * @param shortName 别名简称
	 * @param caterMobile 联系电话
	 * @param caterDetailAdd 详细地址
	 * @param caterBusi 商圈
	 * @param caterBuild 标志性建筑
	 * @param caterZip 邮编
	 * @param caterTime 营业时间
	 * @param caterTransit 公交路线
	 * @param caterDesc 位置描述
	 * @param caterAtmo 商户氛围
	 * @param caterReco 推荐点
	 * @param caterMerIntr 商户简介
	 * @param caterbiaoqian 标签
	 * @param caterDish 招牌菜
	 * @param caterPark 停车位
	 * @param caterLevel 消费档次
	 * @param caterSwingCard 是否刷卡
	 * @param caterArea 面积(m2)
	 * @param caterRoom 包间信息
	 * @param caterBigRoom 大包间
	 * @param caterSmallRoom 小包间
	 * @param caterSeatCap 客容量
	 * @param caterAccReser 是否接受预定
	 * @param caterDeliServ 是否外送服务
	 * @param caterInfoMainte 信息维护
	 * @param x 经度
	 * @param y 纬度
	 * @param mobilePayment 是否手机支付
	 * @return String
	 */
	@Transactional
	public String updateResourceLocal(String userId, String shopId, String caterReg, String caterServ, String caterName,
			String caterStore, String shortName, String caterMobile, String caterDetailAdd, String caterBusi, String caterBuild,
			String caterZip, String caterTime, String caterTransit, String caterDesc, String caterAtmo, String caterReco, 
			String caterMerIntr, String caterbiaoqian, String caterDish, String caterPark, String caterLevel, String caterSwingCard,
			String caterArea, String caterRoom, String caterBigRoom, String caterSmallRoom, String caterSeatCap, 
			String caterAccReser, String caterDeliServ, String caterInfoMainte, String x, String y, String mobilePayment) {
		Resource resource = new Resource();
		//替换营业时间中的中文冒号为英文冒号
		caterTime = caterTime.replaceAll("：", ":");
		String provinceId = ""; //省份ID
		String cityId = ""; //城市ID
		String industryId = ""; //行业ID
		String channelId = ""; //频道ID
		String dataSource = URLConstant.DATA_SOURCE; //数据来源(1-安徽)
		resource.setShopId(shopId); //商户ID
		if(StringUtils.hasText(caterReg)) {
			//根据区域ID查找区域信息
			Areas areas = this.mAreasService.getAreaById(caterReg);
			cityId = areas.getCityid();
			provinceId = areas.getProvinceid();
		}
		resource.setProvinceId(provinceId);
		resource.setCityId(cityId);
		resource.setDistrictId(caterReg);
		if(StringUtils.hasText(caterServ)) {
			//根据服务项目ID获取服务项目信息
			ServiceItem serviceItem = this.mServiceItemService.getEntity(caterServ);
			industryId = serviceItem.getIndustry().getIndustryId();
			channelId = serviceItem.getIndustry().getChannel().getChannelId();
		}
		resource.setChannelId(channelId);
		resource.setTradeId(industryId);
		resource.setBelongId(caterServ);
		resource.setName(caterName);
		resource.setBranchName(caterStore);
		resource.setShortName(shortName);
		resource.setTelno(caterMobile);
		resource.setAddress(caterDetailAdd);
		resource.setRegion(caterBusi);
		resource.setLandmark(caterBuild);
		resource.setZipcode(caterZip);
		resource.setOpenTime(caterTime);
		resource.setBusRoute(caterTransit);
		resource.setRoute(caterDesc);
		resource.setFeature(caterAtmo);
		resource.setRecommendation(caterReco);
		resource.setIntroduction(caterMerIntr);
		resource.setTag(caterbiaoqian);
		resource.setSpecialOffer(caterDish); //招牌菜or特色菜
		resource.setParking(caterPark);
		resource.setCost(caterLevel);
		resource.setChargeType(caterSwingCard); //是否刷卡
		resource.setArea(caterArea);
		resource.setPrivateRoom(caterRoom);
		resource.setMaxCapacity(caterBigRoom);
		resource.setMinCapacity(caterSmallRoom);
		resource.setCapacity(caterSeatCap);
		resource.setReservation(caterAccReser);
		resource.setDeliveryService(caterDeliServ);
		resource.setInfoMaintain(caterInfoMainte);
		resource.setX(x);
		resource.setY(y);
		resource.setMobilePayment(mobilePayment);
		resource.setAddMan(userId);
		resource.setAddDate(new Date());
		resource.setDataSource(dataSource);
		resource.setCheckFlag("1"); //是否经过审核(0-是,1-否)
		resource.setDataFlag("1"); //数据标识(0-新增、1-更新、2-删除或为空白)
		resource.setDelFlag("0"); //删除标志(0-未删除 1-已删除)
		resource.setPassFlag("0"); //审核结果(0-默认值,1-通过,-1-不通过)
		resource.setCollectorId(URLConstant.COLLECTOR_ID);
		String result = "";
		try {
			result = this.updateResourceCenter(userId, shopId, caterReg, caterServ, caterName, caterStore, shortName, caterMobile, 
					caterDetailAdd, caterBusi, caterBuild, caterZip, caterTime, caterTransit, caterDesc, caterAtmo, caterReco, 
					caterMerIntr, caterbiaoqian, caterDish, caterPark, caterLevel, caterSwingCard, caterArea, caterRoom, 
					caterBigRoom, caterSmallRoom, caterSeatCap, caterAccReser, caterDeliServ, caterInfoMainte, x, y, 
					mobilePayment, provinceId, cityId, industryId, channelId, dataSource);
			//解析中央库返回的json数据
			JSONObject object = JSONObject.parseObject(result);
			//向中央信息库中新增商户信息成功,将商户信息持久化至数据库
			if("1".equals(object.get("status").toString())) {
				String state = ""; //入库状态(1-入库等待,2-入库中,3-入库完成,4-入库失败)
		        String infoId = ""; //流水号
				JSONArray object2 = object.getJSONArray("result");
				for(int i = 0; i < object2.size(); i++) {
					JSONObject config = object2.getJSONObject(i);
		        	state = config.getString("state");
		        	infoId = config.getString("info_id");
				}
				resource.setInfoId(infoId);
				resource.setState(state);
				this.mResourceDao.save(resource);
			}
			logger.debug("#########  更新中央信息库中新增商户信息成功!  #########");
		} catch (Exception e) {
			e.printStackTrace();
			logger.debug("#########  更新中央信息库中新增商户信息失败!  #########");
		}
		return result;
	}
	
	/**
	 * 信息更新接口-更新中央信息库中的商户信息.
	 * @param userId 用户ID
	 * @param shopId 商户ID
	 * @param caterReg 区/县ID
	 * @param caterServ 服务项目ID
	 * @param caterName 商户名称
	 * @param caterStore 分店名
	 * @param shortName 别名简称
	 * @param caterMobile 联系电话
	 * @param caterDetailAdd 详细地址
	 * @param caterBusi 商圈
	 * @param caterBuild 标志性建筑
	 * @param caterZip 邮编
	 * @param caterTime 营业时间
	 * @param caterTransit 公交路线
	 * @param caterDesc 位置描述
	 * @param caterAtmo 商户氛围
	 * @param caterReco 推荐点
	 * @param caterMerIntr 商户简介
	 * @param caterbiaoqian 标签
	 * @param caterDish 招牌菜
	 * @param caterPark 停车位
	 * @param caterLevel 消费档次
	 * @param caterSwingCard 是否刷卡
	 * @param caterArea 面积(m2)
	 * @param caterRoom 包间信息
	 * @param caterBigRoom 大包间
	 * @param caterSmallRoom 小包间
	 * @param caterSeatCap 客容量
	 * @param caterAccReser 是否接受预定
	 * @param caterDeliServ 是否外送服务
	 * @param caterInfoMainte 信息维护
	 * @param x 经度
	 * @param y 纬度
	 * @param mobilePayment 是否手机支付
	 * @param provinceId 省份ID
	 * @param cityId 城市ID
	 * @param industryId 行业ID
	 * @param channelId 频道ID
	 * @param dataSource 数据来源
	 * @return String
	 * @throws Exception
	 */
	@Transactional
	public String updateResourceCenter(String userId, String shopId, String caterReg, String caterServ, String caterName,
			String caterStore, String shortName, String caterMobile, String caterDetailAdd, String caterBusi, String caterBuild,
			String caterZip, String caterTime, String caterTransit, String caterDesc, String caterAtmo, String caterReco, 
			String caterMerIntr, String caterbiaoqian, String caterDish, String caterPark, String caterLevel, String caterSwingCard,
			String caterArea, String caterRoom, String caterBigRoom, String caterSmallRoom, String caterSeatCap, String caterAccReser, 
			String caterDeliServ, String caterInfoMainte, String x, String y, String mobilePayment, String provinceId, String cityId,
			String industryId, String channelId, String dataSource) throws Exception {
		System.out.println("================================================================================");
		System.out.println("商户ID               : " + shopId);
		System.out.println("编码前name           : " + caterName);
		System.out.println("编码前caterPark      : " + caterPark);
		System.out.println("编码前caterArea      : " + caterArea);
		System.out.println("编码前caterSwingCard : " + caterSwingCard);
		System.out.println("编码前mobilePayment  : " + mobilePayment);
		System.out.println("编码前caterAccReser  : " + caterAccReser);
		System.out.println("编码前caterDeliServ  : " + caterDeliServ);
		System.out.println("================================================================================");
		String xyLevel = URLConstant.XY_LEVEL;
		String isOutbound = URLConstant.IS_OUT_BOUND;
		String ticketPrice = URLConstant.TICKET_PRICE;
		String officialSite = URLConstant.OFFICIAL_SITE;
		userId = URLConstant.COLLECTOR_ID;
		caterName = URLEncoder.encode(caterName, "UTF-8");
		caterStore = URLEncoder.encode(caterStore, "UTF-8");
		shortName = URLEncoder.encode(shortName, "UTF-8");
		caterDetailAdd = URLEncoder.encode(caterDetailAdd, "UTF-8");
		caterBusi = URLEncoder.encode(caterBusi, "UTF-8");
		caterBuild = URLEncoder.encode(caterBuild, "UTF-8");
		caterTransit = URLEncoder.encode(caterTransit, "UTF-8");
		caterDesc = URLEncoder.encode(caterDesc, "UTF-8");
		caterAtmo = URLEncoder.encode(caterAtmo, "UTF-8");
		caterReco = URLEncoder.encode(caterReco, "UTF-8");
		caterMerIntr = URLEncoder.encode(caterMerIntr, "UTF-8");
		caterbiaoqian = URLEncoder.encode(caterbiaoqian, "UTF-8");
		caterDish = URLEncoder.encode(caterDish, "UTF-8");
		caterPark = URLEncoder.encode(caterPark, "UTF-8");
		caterLevel = URLEncoder.encode(caterLevel, "UTF-8");
		caterSwingCard = URLEncoder.encode(caterSwingCard, "UTF-8");
		caterTime = URLEncoder.encode(caterTime, "UTF-8");
		caterArea = URLEncoder.encode(caterArea, "UTF-8");
		caterRoom = URLEncoder.encode(caterRoom, "UTF-8");
		caterAccReser = URLEncoder.encode(caterAccReser, "UTF-8");
		caterDeliServ = URLEncoder.encode(caterDeliServ, "UTF-8");
		caterInfoMainte = URLEncoder.encode(caterInfoMainte, "UTF-8");
		mobilePayment = URLEncoder.encode(mobilePayment, "UTF-8");
		System.out.println("================================================================================");
		System.out.println("编码后name : " + caterName);
		System.out.println("编码后caterPark : " + caterPark);
		System.out.println("编码后caterArea : " + caterArea);
		System.out.println("编码后caterSwingCard : " + caterSwingCard);
		System.out.println("编码后mobilePayment : " + mobilePayment);
		System.out.println("编码后caterAccReser : " + caterAccReser);
		System.out.println("编码后caterDeliServ : " + caterDeliServ);
		System.out.println("================================================================================");
		//URL前缀
		String url = updateResourceUrlPrefix;
		System.out.println("================================================================================");
		System.out.println("更新商户信息URL : " + updateResourceUrlPrefix);
		System.out.println("================================================================================");
		//URL参数
		String parameters = StringUtil.formatMsg(URLConstant.UPDATE_RESOURCE_URL_PARAMETER, shopId, caterName, caterMobile, 
				caterDetailAdd, caterStore, shortName, caterMerIntr, caterReco, caterAtmo, caterDish, provinceId, cityId, 
				caterReg, channelId, industryId, caterServ, x, y, caterBuild, caterBusi, xyLevel, caterbiaoqian, userId, 
				isOutbound, caterZip, caterPark, caterSwingCard, caterTime, caterTransit, caterDesc, caterLevel, caterArea, 
				caterRoom, ticketPrice, caterBigRoom, caterSmallRoom, caterSeatCap, caterAccReser, caterDeliServ, 
				officialSite, mobilePayment, caterInfoMainte, dataSource);
		//处理url中的空格(" "),解决505错误问题(使用%20替换空格)
		parameters = parameters.replaceAll(" ", "%20");
		URL postUrl = new URL(url);
		HttpURLConnection connection = (HttpURLConnection) postUrl.openConnection();
		connection.setDoOutput(true);
		connection.setDoInput(true);
		connection.setInstanceFollowRedirects(false);
		connection.setRequestMethod("POST");
		connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
		connection.setRequestProperty("charset", "UTF-8");
		connection.setRequestProperty("Content-Length", "" + Integer.toString(parameters.getBytes().length));
		connection.setUseCaches(false);
		DataOutputStream out = new DataOutputStream(connection.getOutputStream());
		out.writeBytes(parameters);
		out.flush();
		out.close();
        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
        String line = "";
        String response = "";
        while ((line = reader.readLine()) != null) {
        	response = line;
        }
        reader.close();
        connection.disconnect();
        System.out.println("================================================================================");
		System.out.println("url           : " + (url + "?" + parameters));
		System.out.println("================================================================================");
		System.out.println("返回结果result : " + response);
		System.out.println("================================================================================");
		return response;
	}
	
	/**
	 * 生活(商户)搜索接口-展示商户列表.
	 * @param pid 合作类型
	 * @param vt 接入类型(1-WAP,2-客户端,5-WEB)
	 * @param pt 产品类型(2-商户)
	 * @param ip 用户IP
	 * @param uci 接入地
	 * @param m 手机号
	 * @param ua 手机UA信息
	 * @param ui 用户信息
	 * @param ls 定位串
	 * @param q 查询串
	 * @param pn 查询页数
	 * @param ps 每页条数
	 * @param lpi 省ID
	 * @param lci 市ID
	 * @param lti 行业ID
	 * @param x 经度
	 * @param y 纬度
	 * @param lbb 范围
	 * @param discount 优惠券查询
	 * @param DiscountRate 折扣率
	 * @param address 商圈查询
	 * @param customize 复杂查询参数
	 * @param Zip 是否压缩
	 * @return document
	 * @throws Exception
	 */
	public Document search(String pid, String vt, String pt, String ip, String uci, String m, String ua, String ui, String ls, 
			String q, String pn, String ps, String lpi, String lci, String lti, String x, String y, String lbb, String discount,
			String DiscountRate, String address, String customize, String Zip) throws Exception {
		System.out.println("================================================================================");
		System.out.println("搜索,编码前q : " + q);
		//对查询串(关键字)进行编码
		q = URLEncoder.encode(q, "UTF-8");
		System.out.println("搜索,编码后q : " + q);
		System.out.println("================================================================================");
		//对可能没有传的参数的值(null)置为空("")
		if(!StringUtils.hasText(uci)) {
			uci = "";
		}
		if(!StringUtils.hasText(ui)) {
			ui = "";
		}
		if(!StringUtils.hasText(ls)) {
			ls = "";
		}
		if(!StringUtils.hasText(lti)) {
			lti = "";
		}
		if(!StringUtils.hasText(x)) {
			x = "";
		}
		if(!StringUtils.hasText(y)) {
			y = "";
		}
		if(!StringUtils.hasText(lbb)) {
			lbb = "";
		}
		if(!StringUtils.hasText(discount)) {
			discount = "";
		}
		if(!StringUtils.hasText(DiscountRate)) {
			DiscountRate = "";
		}
		if(!StringUtils.hasText(address)) {
			address = "";
		}
		if(!StringUtils.hasText(customize)) {
			customize = "";
		}
		if(!StringUtils.hasText(Zip)) {
			Zip = "";
		}
		String url = StringUtil.formatMsg(searchShopUrl, pid, vt, pt, ip, uci, m, ua, ui, ls, q, pn, ps, lpi, lci, lti,
				x, y, lbb, discount, DiscountRate, address, customize, Zip);
		//处理参数中的空格(" "),解决505错误问题(使用%20替换空格)
		url = url.replaceAll(" ", "%20");
		System.out.println("================================================================================");
		System.out.println("商户搜索URL : " + searchShopUrl);
		System.out.println("url        : " + url);
		System.out.println("================================================================================");
		
		Date beforeCenter = new Date();
		HttpClient httpClient = new HttpClient();
		httpClient.getParams().setAuthenticationPreemptive(true);
		//创建POST方法的实例
		PostMethod postMethod = new PostMethod(url);
		//使用系统提供的默认的恢复策略
		postMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
		String result = null; //初始化返回结果(String类型)
		byte[] responseBody = null; //初始化返回结果(byte[]类型)
		try {
			//执行getMethod
			int statusCode = httpClient.executeMethod(postMethod);
		    if (statusCode != HttpStatus.SC_OK) {
			    System.err.println("Method failed: " + postMethod.getStatusLine());
		    }
		    //返回结果（byte[]类型） 
		    responseBody = postMethod.getResponseBody();
		    //返回结果(String类型，UTF-8格式)
		    result = new String(responseBody, "UTF-8");
		} catch (IOException e) {
		   e.printStackTrace();
		} finally {
			//释放连接
			postMethod.releaseConnection();
		}
		Date afterCenter = new Date();
		
		//notice: 这里使用与新增/更新接口不同的方法主要是为了较方便的解析中央库返回结果
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.parse(new InputSource(new ByteArrayInputStream(result.getBytes("UTF-8"))));
        Element element = document.getDocumentElement();
        NodeList bookNodes = element.getElementsByTagName("result");
        for(int i = 0; i < bookNodes.getLength(); i++) {
        	NodeList childNodes = bookNodes.item(i).getChildNodes();
        	//对每条记录(result)创建并新增expired节点
        	Node newChild = document.createElement("expired");
        	bookNodes.item(i).appendChild(newChild);
        	//设置expired节点的值(0-无需修改,1-数据缺失,2-数据过期)
        	childNodes = this.nodeList(childNodes);
        }
        Date afterParse = new Date();
        System.out.println("================================================================================");
		System.out.println("中央库请求响应时间 : " + (afterCenter.getTime() - beforeCenter.getTime()));
		System.out.println("结束判断响应时间    : " + (afterParse.getTime() - afterCenter.getTime()));
		System.out.println("返回结果result    : " + result);
		System.out.println("================================================================================");
        return document;
	}
	
	/**
	 * 设置expired节点的值(0-无需修改,1-数据缺失,2-数据过期,3-服务项目ID不存在).
	 * @param childNodes 记录的节点列表
	 * @return NodeList
	 * @throws Exception
	 */
	public NodeList nodeList(NodeList childNodes) throws Exception {
		String nodeName = ""; //节点名称
		String nodeValue = ""; //节点值
		String tradeId = ""; //服务项目ID
		String updateDate = ""; //更新时间
		String expiredValue = "0"; //expired节点的值(初始化为0-无需修改)
		Boolean isBlank = false; //必填字段是否为空
		Boolean isExpired = false; //是否过期
		Node expiredNode = null; //expired节点
		//遍历单条记录,取出服务项目ID、更新时间和expired节点
		for(int i = 0; i < childNodes.getLength(); i++) {
			Node node = childNodes.item(i);
			switch (node.getNodeName()) {
				case "trade_id"   : tradeId = node.getTextContent();  break;
				case "updated_at" : updateDate = node.getTextContent(); break;
				case "expired"    : expiredNode = node; break;
				default           : break;
			}
		}
		//判断服务项目ID是否存在
		if(this.mServiceItemService.isServiceItemExist(tradeId)) { //服务项目ID存在
			ServiceItem serviceItem = this.mServiceItemService.getEntity(tradeId);
			Industry industry = serviceItem.getIndustry();
			Map<String, Object> map = this.mResourcePropertyService.getProperty(industry.getIndustryId());
			//遍历单条记录,判断是否存在必填字段为空
			for(int i = 0; i < childNodes.getLength(); i++) {
				nodeName = childNodes.item(i).getNodeName();
				nodeValue = childNodes.item(i).getTextContent();
				//判断是否存在必填字段为空
				isBlank = this.mServiceItemService.isNodeBlank(map, nodeName, nodeValue);
				if(isBlank) {
					expiredValue = "1"; //存在空值-数据缺失
					break;
				}
			}
			//不存在必填字段为空时,判断是否过期
			if("0".equals(expiredValue)) {
				isExpired = this.mServiceItemService.isExpired(tradeId, updateDate);
				if(isExpired) {
					expiredValue = "2"; //数据过期
				} else {
					expiredValue = "0"; //无需修改
				}
			}
		} else { //服务项目ID不存在
			expiredValue = "3"; //服务项目ID不存在
		}
		//设置expired节点的值
		expiredNode.setTextContent(expiredValue);
		return childNodes;
	}
	
	/**
	 * 商户详情接口-查询商户的详细信息.
	 * @param pid 合作类型(合作方ID)
	 * @param vt 接入类型(1-WAP,2-客户端,5-WEB)
	 * @param pt 产品类型(2-商户)
	 * @param ip 用户访问IP(PC Web)
	 * @param uci 用户手机接入地
	 * @param m 手机号
	 * @param ua 手机UA信息(用户手机的型号)
	 * @param ui 用户信息(Cookie记录的用户信息)
	 * @param ls 定位串
	 * @param ii 索引信息ID(info_id:流水号)
	 * @param Zip 是否压缩
	 * @return String
	 * @throws Exception
	 */
	public String detail(String pid, String vt, String pt, String ip, String uci, String m, String ua, String ui, String ls, 
			String ii, String Zip) throws Exception {
		String url = StringUtil.formatMsg(shopDetailUrl, pid, vt, pt, ip, uci, m, ua, ui, ls, ii, Zip);
		
		System.out.println("================================================================================");
		System.out.println("商户详情URL : " + shopDetailUrl);
		System.out.println("url         : " + url);
		System.out.println("================================================================================");
		
		URL postUrl = new URL(url);
		HttpURLConnection connection = (HttpURLConnection) postUrl.openConnection();
		connection.setDoOutput(true);
		connection.setDoInput(true);
		connection.setRequestMethod("POST");
		connection.setUseCaches(false);
		connection.setInstanceFollowRedirects(true);
		connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
		connection.connect();
        DataOutputStream out = new DataOutputStream(connection.getOutputStream());
        out.flush();
        out.close();
        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),"UTF-8"));
        String line = "";
        String xml = "";
        while ((line = reader.readLine()) != null) {
        	xml = line;
        }
        reader.close();
        connection.disconnect();
		return xml;
	}
	
	/*==========================================  以下两个方法新增于2014-01-21 @author 袁凤建  ==========================================*/
	
	/**
	 * 信息新增接口-通过该接口将商户信息持久化至本地数据库.
	 * @param userId 用户ID
	 * @param caterReg 区/县ID
	 * @param caterServ 服务项目ID
	 * @param caterName 商户名称
	 * @param caterStore 分店名
	 * @param shortName 别名简称
	 * @param caterMobile 联系电话
	 * @param caterDetailAdd 详细地址
	 * @param caterBusi 商圈
	 * @param caterBuild 标志性建筑
	 * @param caterZip 邮编
	 * @param caterTime 营业时间
	 * @param caterTransit 公交路线
	 * @param caterDesc 位置描述
	 * @param caterAtmo 商户氛围
	 * @param caterReco 推荐点
	 * @param caterMerIntr 商户简介
	 * @param caterbiaoqian 标签
	 * @param caterDish 招牌菜
	 * @param caterPark 停车位
	 * @param caterLevel 消费档次
	 * @param caterSwingCard 是否刷卡
	 * @param caterArea 面积(m2)
	 * @param caterRoom 包间信息
	 * @param caterBigRoom 大包间
	 * @param caterSmallRoom 小包间
	 * @param caterSeatCap 客容量
	 * @param caterAccReser 是否接受预定
	 * @param caterDeliServ 是否外送服务
	 * @param caterInfoMainte 信息维护
	 * @param x 经度
	 * @param y 纬度
	 * @param mobilePayment 是否手机支付
	 */
	@Transactional
	public void addResource(String userId, String caterReg, String caterServ, String caterName, String caterStore, 
			String shortName, String caterMobile, String caterDetailAdd, String caterBusi, String caterBuild, String caterZip, 
			String caterTime, String caterTransit, String caterDesc, String caterAtmo, String caterReco, String caterMerIntr, 
			String caterbiaoqian, String caterDish, String caterPark, String caterLevel, String caterSwingCard, String caterArea, 
			String caterRoom, String caterBigRoom, String caterSmallRoom, String caterSeatCap, String caterAccReser, 
			String caterDeliServ, String caterInfoMainte, String x, String y, String mobilePayment) {
		Resource resource = new Resource();
		String provinceId = ""; //省份ID
		String cityId = ""; //城市ID
		String industryId = ""; //行业ID
		String channelId = ""; //频道ID
		String dataSource = URLConstant.DATA_SOURCE; //数据来源(1-安徽)
		if(StringUtils.hasText(caterReg)) {
			//根据区域ID查找区域信息
			Areas areas = this.mAreasService.getAreaById(caterReg);
			cityId = areas.getCityid();
			provinceId = areas.getProvinceid();
		}
		resource.setProvinceId(provinceId);
		resource.setCityId(cityId);
		resource.setDistrictId(caterReg);
		if(StringUtils.hasText(caterServ)) {
			//根据服务项目ID获取服务项目信息
			ServiceItem serviceItem = this.mServiceItemService.getEntity(caterServ);
			industryId = serviceItem.getIndustry().getIndustryId();
			channelId = serviceItem.getIndustry().getChannel().getChannelId();
		}
		resource.setChannelId(channelId);
		resource.setTradeId(industryId);
		resource.setBelongId(caterServ);
		resource.setName(caterName);
		resource.setBranchName(caterStore);
		resource.setShortName(shortName);
		resource.setTelno(caterMobile);
		resource.setAddress(caterDetailAdd);
		resource.setRegion(caterBusi);
		resource.setLandmark(caterBuild);
		resource.setZipcode(caterZip);
		resource.setOpenTime(caterTime);
		resource.setBusRoute(caterTransit);
		resource.setRoute(caterDesc);
		resource.setFeature(caterAtmo);
		resource.setRecommendation(caterReco);
		resource.setIntroduction(caterMerIntr);
		resource.setTag(caterbiaoqian);
		resource.setSpecialOffer(caterDish); //招牌菜/特色菜
		resource.setParking(caterPark);
		resource.setCost(caterLevel);
		resource.setChargeType(caterSwingCard); //是否刷卡
		resource.setArea(caterArea);
		resource.setPrivateRoom(caterRoom);
		resource.setMaxCapacity(caterBigRoom);
		resource.setMinCapacity(caterSmallRoom);
		resource.setCapacity(caterSeatCap);
		resource.setReservation(caterAccReser);
		resource.setDeliveryService(caterDeliServ);
		resource.setInfoMaintain(caterInfoMainte);
		resource.setX(x);
		resource.setY(y);
		resource.setMobilePayment(mobilePayment);
		resource.setAddMan(userId);
		resource.setAddDate(new Date());
		resource.setDataSource(dataSource);
		resource.setCheckFlag("1"); //是否经过审核(0-是,1-否)
		resource.setDataFlag("0"); //数据标识(0-新增、1-更新、2-删除或为空白)
		resource.setDelFlag("0"); //删除标志(0-未删除 1-已删除)
		resource.setPassFlag("0"); //审核结果(0-默认值,1-通过,-1-不通过)
		resource.setCollectorId(URLConstant.COLLECTOR_ID);
		this.mResourceDao.save(resource);
	}
	
	/**
	 * 信息更新接口-通过该接口,更新中央信息库中的商户信息,并将商户信息持久化至本地数据库.
	 * @param userId 用户ID
	 * @param shopId 商户ID
	 * @param caterReg 区/县ID
	 * @param caterServ 服务项目ID
	 * @param caterName 商户名称
	 * @param caterStore 分店名
	 * @param shortName 别名简称
	 * @param caterMobile 联系电话
	 * @param caterDetailAdd 详细地址
	 * @param caterBusi 商圈
	 * @param caterBuild 标志性建筑
	 * @param caterZip 邮编
	 * @param caterTime 营业时间
	 * @param caterTransit 公交路线
	 * @param caterDesc 位置描述
	 * @param caterAtmo 商户氛围
	 * @param caterReco 推荐点
	 * @param caterMerIntr 商户简介
	 * @param caterbiaoqian 标签
	 * @param caterDish 招牌菜
	 * @param caterPark 停车位
	 * @param caterLevel 消费档次
	 * @param caterSwingCard 是否刷卡
	 * @param caterArea 面积(m2)
	 * @param caterRoom 包间信息
	 * @param caterBigRoom 大包间
	 * @param caterSmallRoom 小包间
	 * @param caterSeatCap 客容量
	 * @param caterAccReser 是否接受预定
	 * @param caterDeliServ 是否外送服务
	 * @param caterInfoMainte 信息维护
	 * @param x 经度
	 * @param y 纬度
	 * @param mobilePayment 是否手机支付
	 */
	@Transactional
	public void updateResource(String userId, String shopId, String caterReg, String caterServ, String caterName,
			String caterStore, String shortName, String caterMobile, String caterDetailAdd, String caterBusi, String caterBuild,
			String caterZip, String caterTime, String caterTransit, String caterDesc, String caterAtmo, String caterReco, 
			String caterMerIntr, String caterbiaoqian, String caterDish, String caterPark, String caterLevel, String caterSwingCard,
			String caterArea, String caterRoom, String caterBigRoom, String caterSmallRoom, String caterSeatCap, 
			String caterAccReser, String caterDeliServ, String caterInfoMainte, String x, String y, String mobilePayment) {
		Resource resource = new Resource();
		String provinceId = ""; //省份ID
		String cityId = ""; //城市ID
		String industryId = ""; //行业ID
		String channelId = ""; //频道ID
		String dataSource = URLConstant.DATA_SOURCE; //数据来源(1-安徽)
		resource.setShopId(shopId); //商户ID
		if(StringUtils.hasText(caterReg)) {
			//根据区域ID查找区域信息
			Areas areas = this.mAreasService.getAreaById(caterReg);
			cityId = areas.getCityid();
			provinceId = areas.getProvinceid();
		}
		resource.setProvinceId(provinceId);
		resource.setCityId(cityId);
		resource.setDistrictId(caterReg);
		if(StringUtils.hasText(caterServ)) {
			//根据服务项目ID获取服务项目信息
			ServiceItem serviceItem = this.mServiceItemService.getEntity(caterServ);
			industryId = serviceItem.getIndustry().getIndustryId();
			channelId = serviceItem.getIndustry().getChannel().getChannelId();
		}
		resource.setChannelId(channelId);
		resource.setTradeId(industryId);
		resource.setBelongId(caterServ);
		resource.setName(caterName);
		resource.setBranchName(caterStore);
		resource.setShortName(shortName);
		resource.setTelno(caterMobile);
		resource.setAddress(caterDetailAdd);
		resource.setRegion(caterBusi);
		resource.setLandmark(caterBuild);
		resource.setZipcode(caterZip);
		resource.setOpenTime(caterTime);
		resource.setBusRoute(caterTransit);
		resource.setRoute(caterDesc);
		resource.setFeature(caterAtmo);
		resource.setRecommendation(caterReco);
		resource.setIntroduction(caterMerIntr);
		resource.setTag(caterbiaoqian);
		resource.setSpecialOffer(caterDish); //招牌菜or特色菜
		resource.setParking(caterPark);
		resource.setCost(caterLevel);
		resource.setChargeType(caterSwingCard); //是否刷卡
		resource.setArea(caterArea);
		resource.setPrivateRoom(caterRoom);
		resource.setMaxCapacity(caterBigRoom);
		resource.setMinCapacity(caterSmallRoom);
		resource.setCapacity(caterSeatCap);
		resource.setReservation(caterAccReser);
		resource.setDeliveryService(caterDeliServ);
		resource.setInfoMaintain(caterInfoMainte);
		resource.setX(x);
		resource.setY(y);
		resource.setMobilePayment(mobilePayment);
		resource.setAddMan(userId);
		resource.setAddDate(new Date());
		resource.setDataSource(dataSource);
		resource.setCheckFlag("1"); //是否经过审核(0-是,1-否)
		resource.setDataFlag("1"); //数据标识(0-新增、1-更新、2-删除或为空白)
		resource.setDelFlag("0"); //删除标志(0-未删除 1-已删除)
		resource.setPassFlag("0"); //审核结果(0-默认值,1-通过,-1-不通过)
		resource.setCollectorId(URLConstant.COLLECTOR_ID);
		this.mResourceDao.save(resource);
	}
}